
            var btn = document.getElementById("btn");
            var username = document.getElementById("username");
            var password = document.getElementById("password");

            btn.onclick = async function () {
                  var options = {
                        url: "http://127.0.0.1:8888/users/login",
                        type: "POST",
                        data: {
                              username: username.value,
                              password: password.value
                        },
                        dataType : "json"
                  }
                  $.ajax(options)
                  .done(function ( data ) {
                             
                        switch (data.code) {
                              case 0:
                                    errorTip(data.message);
                                    break;
                              case 1:
                                    successTip(data.message);

                                    setTimeout(function () {
                                                location.href = "./etao1.html"
                                       
                                    }, 2000)
                      
                                    setCookie("userid", data.user.id);
                                    setCookie("token", data.token, {
                                          expires: 10
                                    });

                                    break;
                        }
                  })

            }

            var tip= document.getElementById("tip");

            function errorTip(msg) {
                  tip.style.display = "block";
                  tip.classList.remove("success");
                  tip.classList.add("danger");

                  tip.innerHTML = msg;

                  setTimeout(function () {
                        tip.style.display = "none";
                  }, 2000)
            }
            function successTip(msg) {
                  tip.classList.remove("danger");
                  tip.classList.add("success");
                 tip.style.display = "block";
                 tip.innerHTML = msg;

                  setTimeout(function () {
                        tip.style.display = "none";
                  }, 2000)
            }